package com.example.globaldemo.valve;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动填充器
 *
 * @author lc
 * @since 2022-01-11 15:23:15
 */
@Component
public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Date now = DateUtil.date();
        this.setFieldValByName("updateDate",now ,metaObject);
        this.setFieldValByName("createDate", now,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateDate", DateUtil.date(),metaObject);
    }
}
